package com.qf.controller;

import com.qf.stream.Sender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {

    private Sender sender;
    @Autowired
    public void setSender(Sender sender) {
        this.sender = sender;
    }

    @GetMapping("/send")
    public String sendMessage(String msg){
//         发送一个消息    获取了一个消息通道
        MessageChannel messageChannel = sender.messageChannel();
//        通过消息的通道发送消息

        messageChannel.send(new GenericMessage<String>(msg));

        return "发送者";
    }
}
